<template>
  <div class="address">
    <div class="address-header">
      <span class="iconfont" @click="back">&#xe612;</span>
      <div class='title'>管理收货地址</div>
      <div class="right"></div>
    </div>
    <div class="address-con">
      <div class="address-add">
        <span class="address-left">配送地址</span>
        <router-link to="add" tag="span" class="address-right">
          +添加地址
        </router-link>
      </div>
      <div
         class="address-person"
         v-for="(list, index) of address"
         :key="index"
         :class="{active:index===$store.state.nowIndex}"
          >
        <div class="address-number">
          <p class="address-left">收货人: {{ list.name }}</p>
          <p class="address-right">{{ list.iphone }}</p>
        </div>
        <div class="address-more">
          收货地址: {{ list.zone }} {{ list.detail }}
        </div>
        <div class="address-bom">
          <div class="address-icon">
            <span class="iconfont icons" @click="rubbish(index)">&#xe6d0;</span>
            <span class="iconfont icons">&#xe60b;</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'

export default {
  data() {
    return {
      nowIndex: 0
    }
  },
  // 计算属性
  computed: {
    address() {
      return this.$store.state.address
    },
    ...mapGetters(
      ["this.$store.state.address"],
      ["this.$store.state.nowIndex"]
    )
  },
  methods: {
    back: function(){
      this.$router.go(-1)
    },
    // 垃圾桶的方法
    ...mapMutations(['rubbish'])
  },
}
</script>

<style lang="less">
  .address{
    .address-header{
      position: fixed;
      top: 0;
      z-index: 2;
      background: white;
      width: 100%;
      height: 1.5rem;
      color: #777;
      border-bottom: 1px solid #eee;
      span{
        width: 10%;
        float: left;
        height: 1.5rem;
        line-height: 1.5rem;
        font-size: .8rem;
        text-align: center;
      }
      .title{
        width: 80%;
        float: left;
        line-height: 1.5rem;
        text-align: center;
        margin: 0 auto;
        font-size: .5rem;
      }
      .right{
        float: left;
        width: 10%;
        line-height: 1rem;
      }
    }
    .address-con{
      padding-top: 1.5rem;
      .address-add{
        width: 100%;
        height: 1.2rem;
        background: white;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: .42rem;
        .address-left{
          padding-left: .36rem;
        }
        .address-right{
          padding-right: .36rem;
          color: #1296DB;
        }
      }
      .address-person{
        width: 100%;
        margin-top: .2rem;
        background: white;
        .address-number{
          width: 100%;
          display: flex;
          justify-content: space-between;
          padding-top: .2rem;
          line-height: .5rem;
          font-size: .5rem;
          .address-left{
            padding-left: .42rem;
          }
          .address-right{
            padding-right: .42rem;
          }
        }
        .address-more{
          padding: .5rem .42rem .42rem .42rem;
          font-size: .42rem;
          border-bottom: 1px solid #eee;
        }
        .address-bom{
          width: 100%;
          height: 1rem;
          line-height: 1rem;
          display: flex;
          justify-content: flex-end;
          .icons{
            font-size: .5rem;
            color: #999;
            padding-right: .6rem;
          }
        }
      }
    }
  }
</style>
